

const ADD_ITEMNUM = 'ADD_ITEMNUM'
const REMBER_ANSWER = 'REMBER_ANSWER'
const REMBER_TIME = 'REMBER_TIME'
const INITIALIZE_DATA = 'INITIALIZE_DATA'

import { setStore, getStore, removeStore } from '@/util/util'

export const RECORD_USERINFO = 'RECORD_USERINFO'
export const GET_USERINFO = 'GET_USERINFO'
export const RETSET_NAME = 'RETSET_NAME'
export const OUT_LOGIN = 'OUT_LOGIN'
export const DIALOG_LOGIN = 'DIALOG_LOGIN'
export default {
	//点击进入下一题
	[ADD_ITEMNUM](state, num) {
		state.itemNum += num;
	},
	//记录答案
	[REMBER_ANSWER](state, id) {
		state.answerid.push(id);
	},
	/*
	记录做题时间
	 */
	[REMBER_TIME](state) {
		state.timer = setInterval(() => {
			state.allTime++;
		}, 1000)
	},
	/*
	初始化信息，
	 */
	[INITIALIZE_DATA](state) {
		state.itemNum = 1;
		state.allTime = 0;
		state.answerid = [];
	},

	// 记录用户信息
	[RECORD_USERINFO](state, info) {
		state.userInfo = info;
		state.login = true;
		// setStore('user_id', info.user_id);
		setStore('userInfo', info);
	},
	//获取用户信息存入vuex
	[GET_USERINFO](state, info) {
		// if (state.userInfo && (state.userInfo.username !== info.username)) {
		// 	return;
		// };
		// if (!state.login) {
		// 	return
		// }
		if (info) {
			state.userInfo = {...info};
			state.login = true;
		} else {
			state.userInfo = null;
			state.login = false;
		}
	},
	//修改用户名
	[RETSET_NAME](state,username) {
		state.userInfo = Object.assign({}, state.userInfo,{username})
	},

	//退出登录
	[OUT_LOGIN](state) {
		state.userInfo = {};
		state.login = false;
		removeStore('userInfo');
	},
	
	[DIALOG_LOGIN](state) {
		state.userInfo = {};
		state.login = false;
		state.dialog_login = true;
		removeStore('userInfo');
	}
}